define(['angular','app.controllers','services/common/base','filters/common/base','services/xdd/xdd_service'],function(angular,controllers,webUploader,videojs){
    'use strict';
    //添加
    controllers.controller('addGTypeController' ,['$q','$resource','$scope','$http','$uibModal','$uibModalInstance','Base','xddService','model', function ($q,$resource,$scope,$http,$uibModal, $uibModalInstance,Base,xddService,model) {
        var error=function(err){
            console.error(err);
        }
        $scope.cancel = function () {
            $uibModalInstance.dismiss();
        };

        $scope.pId=model.pId;
        $scope.submitGType=function(){
            if($scope.gtype.typeName==undefined||$scope.gtype.typeName==""){
                alert("请输入类别名");
                return false;
            }
            if($scope.gtype.price==""){
                alert("请输入价格");
                return false;
            }
            $scope.gtype.pId=$scope.pId;
            var formData = new FormData();
            if(document.querySelector('input[type="file"]').files[0]!=null){
                formData.append("file",document.querySelector('input[type="file"]').files[0]);
                uploadFile(formData);
            }else{
                alert("此次未上传图片");
                addGtype();
            }

        }
        $scope.priceInput=function(){
            $("#priceInput").val($("#priceInput").val().replace(/[^\-?\d.]/g,''));
        }
        var addGtype=function(){
            xddService.addGtype($scope.gtype,function(data){
                $uibModalInstance.close();
            },error)
        }
        var uploadFile=function (formData) {
            $http({
                method:'POST',
                url:"/dapi/upload/image/icon",
                data: formData,
                headers: {'Content-Type':undefined},
                transformRequest: angular.identity
            }).success(function(data){
                $scope.gtype.iconUrl=data.data;
                addGtype();
            });
        };
    }]);
    //修改gtype
       controllers.controller('updateGTypeController' ,['$http','$q','$resource','$scope','$uibModal','$uibModalInstance','Base','xddService','model', function ($http,$q,$resource,$scope,$uibModal, $uibModalInstance,Base,xddService,model) {
        var error=function(err){
            console.error(err);
        }
        $scope.cancel = function () {
            $uibModalInstance.dismiss();
        };
        $scope.gtype=model.gtype;
        $scope.submitGType=function(){
            if($scope.gtype.typeName==undefined||$scope.gtype.typeName==""){
                alert("请输入类别名");
                return false;
            }
            if($scope.gtype.price==""){
                alert("请输入价格");
                return false;
            }
            var formData = new FormData();
            if(document.querySelector('input[type="file"]').files[0]!=null){
                formData.append("file",document.querySelector('input[type="file"]').files[0]);
                uploadFile(formData);
            }else{
                updateGtype();
            }

        }
        $scope.priceInput=function(){
            $("#priceInput").val($("#priceInput").val().replace(/[^\-?\d.]/g,''));
        }
           var updateGtype=function(){
               xddService.updateGtype($scope.gtype,function(data){
                   $uibModalInstance.close();
               },error)
           }
           var uploadFile=function (formData) {
               $http({
                   method:'POST',
                   url:"/dapi/upload/image/icon",
                   data: formData,
                   headers: {'Content-Type':undefined},
                   transformRequest: angular.identity
               }).success(function(data){
                   $scope.gtype.iconUrl=data.data;
                   updateGtype();
               });
           };

    }]);
    //审核商品
    controllers.controller('reviewGoodsController' ,['$q','$scope','$http','$rootScope','$uibModal','$uibModalInstance','Base','xddService','model', function ($q,$scope,$http,$rootScope,$uibModal, $uibModalInstance,Base,xddService,model) {
        var error=function(err){
            console.error(err);
        }
        $scope.cancel = function () {
            $uibModalInstance.dismiss();
        };
        $scope.goods=model.goods;
        $scope.goodsId=model.goods.id;
        $scope.submitReview=function(){
            if($scope.goods.status=='1'){
                alert("该商品已上架不允许操作");
                return false;
            }
            xddService.goodsCheckStatus($scope.goodsId,$scope.checkStatus,function(data){
                alert("提交成功");
                $uibModalInstance.close();
            },error)
        }
    }]);
    //审核旧物
    controllers.controller('checkOldController' ,['$q','$scope','$http','$rootScope','$uibModal','$uibModalInstance','Base','xddService','model', function ($q,$scope,$http,$rootScope,$uibModal, $uibModalInstance,Base,xddService,model) {
        var error=function(err){
            console.error(err);
        }
        $scope.cancel = function () {
            $uibModalInstance.dismiss();
        };

        $scope.oldId=model.oldId;
        $scope.submitReview=function(){
            xddService.checkOld($scope.oldId,$scope.checkStatus,function(data){
                alert("提交成功");
                $uibModalInstance.close();
            },error)
        }
    }]);
    //审核用户
    controllers.controller('checkUserController' ,['$q','$resource','$scope','$uibModal','$uibModalInstance','Base','xddService','model', function ($q,$resource,$scope,$uibModal, $uibModalInstance,Base,xddService,model) {
        var error=function(err){
            console.error(err);
        }
        $scope.cancel = function () {
            $uibModalInstance.dismiss();
        };

        $scope.user=model.user;


        $scope.submitCheckStatus=function(){
            $scope.user.checkStatus=$scope.checkStatus;
            xddService.userCheckStatus($scope.user,function(data){
                alert("提交成功");
                $uibModalInstance.dismiss();
            },error)
        }




    }]);
    //查看营业执照
    controllers.controller('lookUserYyzzController' ,['$q','$resource','$scope','$uibModal','$uibModalInstance','Base','xddService','model', function ($q,$resource,$scope,$uibModal, $uibModalInstance,Base,xddService,model) {
        var error=function(err){
            console.error(err);
        }
        $scope.cancel = function () {
            $uibModalInstance.dismiss();
        };
        $scope.yyzzUrl=model.yyzzUrl;
    }]);
    //修改订单信息
    controllers.controller('updateOrderController' ,['$q','$resource','$scope','$uibModal','$uibModalInstance','Base','xddService','model', function ($q,$resource,$scope,$uibModal, $uibModalInstance,Base,xddService,model) {
        var error=function(err){
            console.error(err);
        }
        $scope.cancel = function () {
            $uibModalInstance.dismiss();
        };
        $scope.order=model.order;

        $scope.submitOrder=function(){
            xddService.updateOrderInfo($scope.order,function(data){
                $uibModalInstance.close();
            },error)
        }
        $scope.priceInput=function(){
            $("#priceInput").val($("#priceInput").val().replace(/[^\-?\d.]/g,''));
        }


    }]);
    //修改订单信息
    controllers.controller('addCouponController' ,['$q','$resource','$scope','$uibModal','$uibModalInstance','Base','xddService','model', function ($q,$resource,$scope,$uibModal, $uibModalInstance,Base,xddService,model) {
        var error=function(err){
            console.error(err);
        }
        $scope.cancel = function () {
            $uibModalInstance.dismiss();
        };
        $scope.submitCoupon=function(){

            if($scope.coupon.title==undefined||$scope.coupon.title==""){
                alert("请输入名称");
                return false;
            }
            if($scope.coupon.dealPrice==undefined||$scope.coupon.dealPrice==""){
                alert("请输入交易金额");
                return false;
            }
            if($scope.coupon.discountPrice==undefined||$scope.coupon.discountPrice==""){
                alert("请输入优惠金额");
                return false;
            }
            if(parseInt($scope.coupon.dealPrice)<parseInt($scope.coupon.discountPrice)){
                alert("优惠金额必须小于交易金额");
                return false;
            }
            if($scope.coupon.startDate==undefined||$scope.coupon.startDate==""){
                alert("请选择开始时间");
                return false;
            }
            if($scope.coupon.endDate==undefined||$scope.coupon.endDate==""){
                alert("请选择结束时间");
                return false;
            }
            if($scope.coupon.startDate>$scope.coupon.endDate){
                alert("结束时间必须大于开始时间");
                return false;
            }
            xddService.submitCoupon($scope.coupon,function(data){
                alert("添加成功");
                $uibModalInstance.close();
            },error);
        }
        $scope.dealPriceInput=function(){
            $("#dealPrice").val($("#dealPrice").val().replace(/[^\d]/g,''));
        }
        $scope.discountPriceInput=function(){
            $("#discountPrice").val($("#discountPrice").val().replace(/[^\d]/g,''));
        }


    }]);
    controllers.controller('userRoleFPController' ,['$q','$resource','$scope','$uibModal','$uibModalInstance','Base','xddService','model', function ($q,$resource,$scope,$uibModal, $uibModalInstance,Base,xddService,model) {
        var error=function(err){
            console.error(err);
        }
        $scope.cancel = function () {
            $uibModalInstance.dismiss();
        };
        $scope.user=model.user;
        //获取当前用户角色

        var getUserRole=function(){
            xddService.getUserRoleList($scope.user.id,function(data){
                $scope.userRoles=data.data;
            },error);
        }
        getUserRole();
        var getRoleListFun=function(){
            xddService.getAllRoleList(function(data){
                $scope.roleList=data.data;
            },error)
        }
        getRoleListFun();

        $scope.submitUserRole=function(){
            if($scope.checkRole==undefined||$scope.checkRole==""){
                alert("请选择角色");
                return false;
            }
            xddService.addUserRole({userId:$scope.user.id,roleCode:$scope.checkRole},function(){
                alert("添加成功");
                getUserRole();
            },error)
        }
        $scope.deleteUserRole=function(role){
            xddService.deleteUserRole({userId:$scope.user.id,roleCode:role.code},function(){
                alert("删除成功");
                getUserRole();
            },error)

        }



    }]);
    //添加角色
    controllers.controller('roleAddController' ,['$q','$scope','$http','$rootScope','$uibModal','$uibModalInstance','Base','xddService','model', function ($q,$scope,$http,$rootScope,$uibModal, $uibModalInstance,Base,xddService,model) {
        var error=function(err){
            layer.alert(err.message);
        }
        $scope.cancel = function () {
            $uibModalInstance.dismiss();
        };
        $scope.submitRoleFun=function(){
            xddService.addRoleSer($scope.role,function(data){
                alert("添加成功");
                $uibModalInstance.close();
            },error)
        }
        $scope.codeInput=function(){
            $("#codeInput").val($("#codeInput").val().replace(/[\W]/g,''));
        }

    }]);

    //添加消息群发
    controllers.controller('addMessageGroupController' ,['$q','$scope','$http','$rootScope','$uibModal','$uibModalInstance','Base','xddService','model', function ($q,$scope,$http,$rootScope,$uibModal, $uibModalInstance,Base,xddService,model) {
        var error = function (err) {
            layer.alert(err.message);
        }
        $scope.cancel = function () {
            $uibModalInstance.dismiss();
        };
       var addMessageG=function(){
            xddService.addMessageGroup($scope.messageGroup,function(data){
                alert("添加成功")
                $uibModalInstance.close();
            },error)
        }
        var uploadFile=function (formData) {
            $http({
                method:'POST',
                url:"/dapi/upload/image/messageGroup",
                data: formData,
                headers: {'Content-Type':undefined},
                transformRequest: angular.identity
            }).success(function(data){
                $scope.messageGroup.imgUrl=data.data;
                addMessageG();
            });
        };
        $scope.submitMessageGroup=function(){
            var formData = new FormData();
            if(document.querySelector('input[type="file"]').files[0]!=null){
                formData.append("file",document.querySelector('input[type="file"]').files[0]);
            }else{
                alert("请选择文件");
                return false;
            }
            uploadFile(formData);
        }
    }]);

    //修改消息群发
    controllers.controller('updateMessageGroupController' ,['$q','$scope','$http','$rootScope','$uibModal','$uibModalInstance','Base','xddService','model', function ($q,$scope,$http,$rootScope,$uibModal, $uibModalInstance,Base,xddService,model) {
        var error = function (err) {
            layer.alert(err.message);
        }
        $scope.cancel = function () {
            $uibModalInstance.dismiss();
        };
        $scope.messageGroup=model.messageGroup;
       var updateMessageG=function(){
            xddService.updateMessageGroup($scope.messageGroup,function(data){
                alert("修改成功")
                $uibModalInstance.close();
            },error)
        }
        var uploadFile=function (formData) {
            $http({
                method:'POST',
                url:"/dapi/upload/image/messageGroup",
                data: formData,
                headers: {'Content-Type':undefined},
                transformRequest: angular.identity
            }).success(function(data){
                $scope.messageGroup.imgUrl=data.data;
                updateMessageG();
            });
        };
        $scope.submitMessageGroup=function(){
            var formData = new FormData();
            if(document.querySelector('input[type="file"]').files[0]!=null){
                formData.append("file",document.querySelector('input[type="file"]').files[0]);
            }else{
                alert("请选择文件");
                return false;
            }
            uploadFile(formData);
        }
    }]);

    //消息群发人员查看明细
    controllers.controller('detailMessageGroupController' ,['$q','$scope','$http','$rootScope','$uibModal','$uibModalInstance','Base','xddService','model', function ($q,$scope,$http,$rootScope,$uibModal, $uibModalInstance,Base,xddService,model) {
        var error = function (err) {
            layer.alert(err.message);
        }
        $scope.cancel = function () {
            $uibModalInstance.dismiss();
        };
        $scope.messageGroup=model.messageGroup;

        xddService.getMessageGroupId( $scope.messageGroup.id,function(data){
            $scope.messagegroupList = data.data;
        },error);
    }])

    //添加代理商
    controllers.controller('addAgentController' ,['$q','$scope','$http','$rootScope','$uibModal','$uibModalInstance','Base','xddService','model', function ($q,$scope,$http,$rootScope,$uibModal, $uibModalInstance,Base,xddService,model) {
         var error=function(err){
            layer.alert(err.message);
         }
         $scope.cancel = function () {
            $uibModalInstance.dismiss();
         };
        $scope.sortInput=function(){
            $("#sortInput").val($("#sortInput").val().replace(/[^\d.]/g,''));
        }
        var addAgent=function(){
            xddService.addAgent($scope.agent,function(data){
                alert("添加成功")
                $uibModalInstance.close();
            },error)
        }
        var uploadFile=function (formData) {
            $http({
                method:'POST',
                url:"/dapi/upload/image/agentLogo",
                data: formData,
                headers: {'Content-Type':undefined},
                transformRequest: angular.identity
            }).success(function(data){
                $scope.agent.iconUrl=data.data;
                addAgent();
            });
        };
        $scope.submitAgent=function(){
            var formData = new FormData();
            if(document.querySelector('input[type="file"]').files[0]!=null){
                formData.append("file",document.querySelector('input[type="file"]').files[0]);
            }else{
                alert("请选择文件");
            }
            uploadFile(formData);
        }
     }]);
    //添加代理商
    controllers.controller('updateAgentController' ,['$q','$scope','$http','$rootScope','$uibModal','$uibModalInstance','Base','xddService','model', function ($q,$scope,$http,$rootScope,$uibModal, $uibModalInstance,Base,xddService,model) {
        var error=function(err){
            layer.alert(err.message);
        }
        $scope.agent=model.agent;
        $scope.cancel = function () {
            $uibModalInstance.dismiss();
        };
        $scope.sortInput=function(){
            $("#sortInput").val($("#sortInput").val().replace(/[^\d.]/g,''));
        }
        var addAgent=function(){
            xddService.updateAgent($scope.agent,function(data){
                alert("修改成功")
                $uibModalInstance.close();
            },error)
        }
        var uploadFile=function (formData) {
            $http({
                method:'POST',
                url:"/dapi/upload/image/agentLogo",
                data: formData,
                headers: {'Content-Type':undefined},
                transformRequest: angular.identity
            }).success(function(data){
                $scope.agent.iconUrl=data.data;
                addAgent();
            });
        };
        $scope.submitAgent=function(){
            var formData = new FormData();
            if(document.querySelector('input[type="file"]').files[0]!=null){
                formData.append("file",document.querySelector('input[type="file"]').files[0]);
            }else{
                alert("请选择文件");
            }
            uploadFile(formData);
        }
    }]);
    //商品类型一级属性
    controllers.controller('addTypeOneController' ,['$q','$scope','$http','$rootScope','$uibModal','$uibModalInstance','Base','xddService','model', function ($q,$scope,$http,$rootScope,$uibModal, $uibModalInstance,Base,xddService,model) {
        var error=function(err){
            layer.alert(err.message);
        }
        $scope.cancel = function () {
            $uibModalInstance.dismiss();
        };
        $scope.sortInput=function(){
            $("#sortInput").val($("#sortInput").val().replace(/[^\d.]/g,''));
        }
        var addTypeOne=function(){
            xddService.addGTypeOne($scope.typeOne,function(data){
                alert("添加成功")
                $uibModalInstance.close();
            },error)
        }
        var uploadFile=function (formData) {
            $http({
                method:'POST',
                url:"/dapi/upload/image/icon",
                data: formData,
                headers: {'Content-Type':undefined},
                transformRequest: angular.identity
            }).success(function(data){
                $scope.typeOne.iconUrl=data.data;
                addTypeOne();
            });
        };
        $scope.submitTypeOne=function(){
            var formData = new FormData();
            if(document.querySelector('input[type="file"]').files[0]!=null){
                formData.append("file",document.querySelector('input[type="file"]').files[0]);
                uploadFile(formData);
            }else{
                alert("此次未上传图片");
                addTypeOne();
            }

        }
    }]);
    controllers.controller('updateTypeOneController' ,['$q','$scope','$http','$rootScope','$uibModal','$uibModalInstance','Base','xddService','model', function ($q,$scope,$http,$rootScope,$uibModal, $uibModalInstance,Base,xddService,model) {
        var error=function(err){
            layer.alert(err.message);
        }
        $scope.typeOne=model.type;
        $scope.cancel = function () {
            $uibModalInstance.dismiss();
        };
        $scope.sortInput=function(){
            $("#sortInput").val($("#sortInput").val().replace(/[^\d.]/g,''));
        }
        var updateGTypeOne=function(){
            xddService.updateGTypeOne($scope.typeOne,function(data){
                alert("修改成功")
                $uibModalInstance.close();
            },error)
        }
        var uploadFile=function (formData) {
            $http({
                method:'POST',
                url:"/dapi/upload/image/icon",
                data: formData,
                headers: {'Content-Type':undefined},
                transformRequest: angular.identity
            }).success(function(data){
                $scope.typeOne.iconUrl=data.data;
                updateGTypeOne();
            });
        };
        $scope.submitTypeOne=function(){
            var formData = new FormData();
            if(document.querySelector('input[type="file"]').files[0]!=null){
                formData.append("file",document.querySelector('input[type="file"]').files[0]);
                uploadFile(formData);
            }else{
                updateGTypeOne();
            }

        }
    }]);
    controllers.controller('addGStyleController' ,['$q','$resource','$scope','$uibModal','$uibModalInstance','Base','xddService','model', function ($q,$resource,$scope,$uibModal, $uibModalInstance,Base,xddService,model) {
        var error=function(err){
            console.error(err);
        }
        $scope.cancel = function () {
            $uibModalInstance.dismiss();
        };
        $scope.pId=model.pId;
        $scope.submitGStyle=function(){
            if($scope.gstyle.typeName==undefined||$scope.gstyle.typeName==""){
                alert("请输入名称");
                return false;
            }
            $scope.gstyle.pId=$scope.pId;
            xddService.addGStyle($scope.gstyle,function(data){
                $uibModalInstance.close();
            },error)
        }
        $scope.priceInput=function(){
            $("#priceInput").val($("#priceInput").val().replace(/[^\-?\d.]/g,''));
        }

    }]);
    //修改gtype
    controllers.controller('updateGStyleController' ,['$q','$resource','$scope','$uibModal','$uibModalInstance','Base','xddService','model', function ($q,$resource,$scope,$uibModal, $uibModalInstance,Base,xddService,model) {
        var error=function(err){
            console.error(err);
        }
        $scope.cancel = function () {
            $uibModalInstance.dismiss();
        };
        $scope.gstyle=model.gstyle;
        $scope.submitGStyle=function(){
            if($scope.gstyle.typeName==undefined||$scope.gstyle.typeName==""){
                alert("请输入名称");
                return false;
            }
            xddService.updateGStyle($scope.gstyle,function(data){
                $uibModalInstance.close();
            },error)
        }
        $scope.priceInput=function(){
            $("#priceInput").val($("#priceInput").val().replace(/[^\-?\d.]/g,''));
        }

    }]);
    //添加品型
    controllers.controller('addPXController' ,['$q','$resource','$scope','$uibModal','$uibModalInstance','Base','xddService','model', function ($q,$resource,$scope,$uibModal, $uibModalInstance,Base,xddService,model) {
        var error=function(err){
            console.error(err);
        }
        $scope.cancel = function () {
            $uibModalInstance.dismiss();
        };
        $scope.pId=model.pId;
        $scope.submitPX=function(){
            if($scope.px.title==undefined||$scope.px.title==""){
                alert("请输入名称");
                return false;
            }
            $scope.px.pId=$scope.pId;
            xddService.addPX($scope.px,function(data){
                $uibModalInstance.close();
            },error)
        }
        $scope.priceInput=function(){
            $("#priceInput").val($("#priceInput").val().replace(/[^\-?\d.]/g,''));
        }

    }]);
    //修改品型
    controllers.controller('updatePXController' ,['$q','$resource','$scope','$uibModal','$uibModalInstance','Base','xddService','model', function ($q,$resource,$scope,$uibModal, $uibModalInstance,Base,xddService,model) {
        var error=function(err){
            console.error(err);
        }
        $scope.cancel = function () {
            $uibModalInstance.dismiss();
        };
        $scope.px=model.px;
        $scope.submitPX=function(){
            if($scope.px.title==undefined||$scope.px.title==""){
                alert("请输入名称");
                return false;
            }
            xddService.updatePX($scope.px,function(data){
                $uibModalInstance.close();
            },error)
        }
        $scope.priceInput=function(){
            $("#priceInput").val($("#priceInput").val().replace(/[^\-?\d.]/g,''));
        }

    }]);
    //添加App首页轮播图片
    controllers.controller('addAppPicController' ,['$q','$scope','$http','$rootScope','$uibModal','$uibModalInstance','Base','xddService','model', function ($q,$scope,$http,$rootScope,$uibModal, $uibModalInstance,Base,xddService,model) {
        var error=function(err){
            layer.alert(err.message);
        }
        $scope.cancel = function () {
            $uibModalInstance.dismiss();
        };
        $scope.sortInput=function(){
            $("#sortInput").val($("#sortInput").val().replace(/[^\d.]/g,''));
        }
        var addAppPic=function(){
            xddService.addAppPic($scope.appPic,function(data){
                alert("添加成功")
                $uibModalInstance.close();
            },error)
        }
        var uploadFile=function (formData) {
            $http({
                method:'POST',
                url:"/dapi/upload/image/appPic",
                data: formData,
                headers: {'Content-Type':undefined},
                transformRequest: angular.identity
            }).success(function(data){
                $scope.appPic.iconUrl=data.data;
                addAppPic();
            });
        };
        $scope.submitAppPic=function(){
            var formData = new FormData();
            if(document.querySelector('input[type="file"]').files[0]!=null){
                formData.append("file",document.querySelector('input[type="file"]').files[0]);
            }else{
                alert("请选择文件");
                return false;
            }
            uploadFile(formData);
        }
    }]);
    //修改App首页轮播图片
    controllers.controller('updateAppPicController' ,['$q','$scope','$http','$rootScope','$uibModal','$uibModalInstance','Base','xddService','model', function ($q,$scope,$http,$rootScope,$uibModal, $uibModalInstance,Base,xddService,model) {
        var error=function(err){
            layer.alert(err.message);
        }
        $scope.appPic=model.appPic;
        $scope.cancel = function () {
            $uibModalInstance.dismiss();
        };
        $scope.sortInput=function(){
            $("#sortInput").val($("#sortInput").val().replace(/[^\d.]/g,''));
        }
        var updateAppPic=function(){
            xddService.updateAppPic($scope.appPic,function(data){
                alert("修改成功")
                $uibModalInstance.close();
            },error)
        }
        var uploadFile=function (formData) {
            $http({
                method:'POST',
                url:"/dapi/upload/image/appPic",
                data: formData,
                headers: {'Content-Type':undefined},
                transformRequest: angular.identity
            }).success(function(data){
                $scope.appPic.iconUrl=data.data;
                updateAppPic();
            });
        };
        $scope.submitAppPic=function(){
            var formData = new FormData();
            if(document.querySelector('input[type="file"]').files[0]!=null){
                formData.append("file",document.querySelector('input[type="file"]').files[0]);
            }else{
                alert("请选择文件");
                return false;
            }
            uploadFile(formData);
        }
    }]);
});